/**
 * Copyright (C), 2021, 因特驰
 * FileName: BackstageController
 * Author:   李晋武
 * Date:     2021/7/13 16:21
 * Description:
 * History:
 * 李晋武          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.esc.controller;

import com.esc.model.*;
import com.esc.service.*;
import com.esc.util.PageResult;
import com.esc.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author Yun
 * @create 2021/7/13
 * @since 1.0.0
 */
@Controller
@RequestMapping("backstage")
public class BackstageController {

    @Autowired
    private BuyerService buyerService;
    @Autowired
    private SellerService sellerService;
    @Autowired
    private StatusService statusService;
    @Autowired
    private GuanggaoService guanggaoService;
    @Autowired
    private ZixunService zixunService;


    //登陆后台
    @RequestMapping("login")
    public String login(){
        return "admin/login";
    }

    //初始化后台页面
    @RequestMapping("index")
    public String index(){
        return "index";
    }

    /*
    买车用户-开始
     */
    //去查询买车用户集
    @RequestMapping("shouBuyer")
    public String shouBuyer(Integer queryId,Model model){
        model.addAttribute("queryId",queryId);
        return "buyer/showBuyer";
    }
    //查询买车用户列表
    @RequestMapping("queryBuyerList")
    @ResponseBody
    public PageResult queryBuyerList(PageUtil<Buyer> pageUtil, Buyer buyer,Integer queryId){
        return buyerService.queryBuyerList(pageUtil,queryId);
    }
    //删除买车用户-状态删除
    @RequestMapping("updateBuyerStauts")
    @ResponseBody
    public void updateBuyerStauts(Integer buyerid,Integer status){
        buyerService.updateBuyerStauts(buyerid,status);
    }
    //去修改用户信息
    @RequestMapping("toUpdate")
    public String toUpdate(Integer buyerid, Model model){
        model.addAttribute("statusList",statusService.queryStatusList());
        model.addAttribute("buyer",buyerService.queryBuyerById(buyerid));
        return "buyer/updateBuyer";
    }
    @RequestMapping("updateBuyer")
    @ResponseBody
    public void updateBuyer(Buyer buyer,Integer statusid){
        Status status = new Status();
        status.setStatusid(statusid);
        buyer.setStatus(status);
        buyerService.updateBuyer(buyer);
    }
    /*
    买车用户-结束
     */

    /*
    卖车用户-开始
     */
    //去查询卖车用户集
    @RequestMapping("shouSeller")
    public String shouSell(Integer queryId,Model model){
        model.addAttribute("queryId",queryId);
        return "seller/showSell";
    }
    //查询卖车用户列表
    @RequestMapping("querySellerList")
    @ResponseBody
    public PageResult querySellerList(PageUtil<Seller> pageUtil, Seller seller, Integer queryId){
        return sellerService.querySellerList(pageUtil,queryId);
    }
    //删除卖车用户-状态删除
    @RequestMapping("updateSellerStauts")
    @ResponseBody
    public void updateSellerStauts(Integer sellerid,Integer status){
        sellerService.updateSellerStauts(sellerid,status);
    }
    //去修改用户信息
    @RequestMapping("toUpdateSeller")
    public String toUpdateSeller(Integer sellerid, Model model){
        model.addAttribute("statusList",statusService.queryStatusList());
        model.addAttribute("seller",sellerService.querySellerById(sellerid));
        return "seller/updateSeller";
    }
    //修改卖车用户信息
    @RequestMapping("updateSeller")
    @ResponseBody
    public void updateSeller(Seller seller,Integer statusid){
        Status status = new Status();
        status.setStatusid(statusid);
        seller.setStatus(status);
        sellerService.updateSeller(seller);
    }
    /*
    卖车用户-结束
     */


    /*
    广告投放-开始
     */
    //广告查询
    @RequestMapping("queryGuanggaoList")
    public String queryGuanggaoList(Integer queryId,Model model){
        List<Guanggao> guanggaoList = guanggaoService.queryGuanggaoList(queryId);
        model.addAttribute("guanggaoList",guanggaoList);
        if (queryId==1){
            return "guanggao/showLunbo";
        }else {
            return "guanggao/showFudong";
        }
    }
    //查询单个广告
    @RequestMapping("queryGuanggaoById")
    @ResponseBody
    public String queryGuanggaoById(Integer guanggaoid){
        Guanggao guanggao =  guanggaoService.queryGuanggaoById(guanggaoid);
        return guanggao.getGuanggaoimg();
    }
    //去修改
    @RequestMapping("toUpdateGuanggao")
    public String toUpdateGuanggao(Integer guanggaoid,Model model){
        Guanggao guanggao = guanggaoService.queryGuanggaoById(guanggaoid);
        model.addAttribute("guanggao",guanggao);
        return "guanggao/updateGuanggao";
    }
    //广告修改
    @RequestMapping("updateGuanggao")
    @ResponseBody
    public void updateGuanggao(Guanggao guanggao){
        guanggaoService.updateGuanggao(guanggao);
    }
    /*
    广告投放结束
     */


    /*
    资讯管理-开始
     */
    //去添加
    @RequestMapping("toAddZixun")
    public String toAddZixun(){
        return "zixun/addZixun";
    }
    //添加资讯
    @RequestMapping("addZixun")
    @ResponseBody
    public void addZixun(Zixun zixun){
        zixunService.addZixun(zixun);
    }
    //去查询
    @RequestMapping("showZixun")
    public String showZixun(Integer queryId, Model model){
        model.addAttribute("queryId",queryId);
        return "zixun/showZixun";
    }
    //资讯查询 | 回收资讯
    @RequestMapping("queryZixunList")
    @ResponseBody
    public PageResult queryZixunList(PageUtil<Zixun> pageUtil,Zixun zixun,Integer queryId){
        pageUtil.setT(zixun);
        return zixunService.queryZixunList(pageUtil,queryId);
    }

    //查看详情
    @RequestMapping("lookZixunContent")
    public String queryZixunById(Integer zixunid,Model model){
        Zixun zixun = zixunService.queryZixunById(zixunid);
        model.addAttribute("zixun",zixun);
        return "zixun/lookZixunContent";
    }

    //去修改
    @RequestMapping("toUpdateZixun")
    public String toUpdateZixun(Integer zixunid,Model model){
        Zixun zixun = zixunService.queryZixunById(zixunid);
        model.addAttribute("zixun",zixun);
        return "zixun/updateZixun";
    }

    //修改资讯
    @RequestMapping("updateZixun")
    @ResponseBody
    public void updateZixun(Zixun zixun){
        zixunService.updateZixun(zixun);
    }

    //删除资讯-删除状态
    @RequestMapping("updateZixunStatus")
    @ResponseBody
    public void updateZixunStatus(Zixun zixun){
        zixunService.updateZixunStatus(zixun);
    }

    //删除资讯-磁盘删除
    @RequestMapping("deleteZixun")
    @ResponseBody
    public void deleteZixun(Integer zixunid){
        zixunService.deleteZixun(zixunid);
    }

    //多选删除-删除状态

    //多选删除-磁盘删除


    /*
    资讯管理-结束
     */
}